import axios from '@/utils/request'

export function login(data) {
  return axios({
    url: '/identity-login/login',
    method: 'post',
    data
  })
}

export function getInfo() {
  return axios({
    url: '/identity-login/getcuruser',
    method: 'get'
  })
}

export function logout() {
  return axios({
    url: '/identity-login/logout',
    method: 'post'
  })
}

export async function getbyId(id){
  const res = await axios.get(`/identity/users/${id}`);
  if (res.code == 1) {
    return res.data;
  } else {
    return Promise.reject(new Error(res.message));
  }
}

export async function getUserByPaged(data){
  const res = await axios.get('/identity/users',{
    params: data
  });
  if (res.code == 1) {
    return res.data;
  } else {
    return Promise.reject(new Error(res.message));
  }
}

export async function addUser(data){
  const res = await axios.post('/identity/users', data);
  if (res.code == 1) {
    return res.data;
  } else {
    return Promise.reject(new Error(res.message));
  }
}

export async function deleteUser(id){
  const res = await axios.delete(`/identity/users/${id}`);
  if (res.code == 1) {
    return res.data;
  } else {
    return Promise.reject(new Error(res.message));
  }
}

export async function updateUser(id,data){
  const res = await axios.put(`/identity/users/${id}`, data);
  if (res.code == 1) {
    return res.data;
  } else {
    return Promise.reject(new Error(res.message));
  }
}
